<script setup lang="ts">
import { LeftCircleOutlined, RightCircleOutlined } from "@ant-design/icons-vue";
import MyInfo from "@/views/Home/MyInfo.vue";
import Tags from "@/views/Home/Tags.vue";
import CategoryCount from "@/views/Home/CategoryCount.vue";
import RecentArticles from "@/views/Home/RecentArticles.vue";
import Article2 from "@/views/Home/Article_2.vue";
import { postApi } from "@/api";
import { onMounted, ref } from "vue";
import type { HotArticlesVo } from "@/type";
import { useRouter } from "vue-router";

const router = useRouter();
const hotSwiper = ref<HotArticlesVo[]>([]);
const getHot = async () => {
  // 获取热门文章
  hotSwiper.value = await postApi.getHot();
};
const toItem = (item: HotArticlesVo) => {
  router.push({
    name: "blogItem",
    params: {
      id: item.id,
      title: item.title,
    },
  });
};
onMounted(() => {
  getHot();
});
</script>

<template>
  <!-- 主体内容 -->
  <div
    class="max-w-7xl mx-auto px-4 pt-24 pb-8 flex flex-col lg:flex-row lg:space-x-8"
  >
    <!-- 主内容区 -->
    <div class="w-full lg:w-[calc(100%-20rem)]">
      <!-- 添加轮播图 -->
      <a-carousel
        autoplay
        arrows
        class="animate__animated animate__fadeInDown mb-3"
      >
        <template #prevArrow>
          <div class="custom-slick-arrow" style="left: 10px; z-index: 1">
            <left-circle-outlined />
          </div>
        </template>
        <template #nextArrow>
          <div class="custom-slick-arrow" style="right: 10px">
            <right-circle-outlined />
          </div>
        </template>
        <div class="item-img" v-for="(item, index) in hotSwiper" :key="index">
          <div
            class="relative overflow-hidden rounded-lg"
            style="cursor: pointer"
            @click="toItem(item)"
          >
            <img class="w-full img" :src="item.coverImage" :alt="item.title" />
            <!-- 添加渐变蒙版 + 文字居中 -->
            <div
              class="absolute inset-0 flex items-end bg-gradient-to-t from-black/30 to-transparent p-4"
            >
              <h3 class="text-white text-lg font-bold drop-shadow-md">
                {{ item.title }}
              </h3>
            </div>
          </div>
        </div>
      </a-carousel>
      <Article2 />
      <!-- <Article/> -->
    </div>
    <!-- 侧边栏 - 移动端变为底部 -->
    <div class="w-full lg:w-80 space-y-6 mt-8 lg:mt-0">
      <!-- 个人信息 -->
      <MyInfo />
      <!-- 分类统计 -->
      <CategoryCount />
      <!-- 标签云 -->
      <Tags />
      <!-- 最新文章 -->
      <RecentArticles />
    </div>
  </div>
</template>

<style scoped>
:deep(.slick-slide) {
  text-align: center;
  overflow: hidden;
  height: 270px;
}
.img {
  height: 270px !important;
}

:deep(.slick-arrow.custom-slick-arrow) {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  transition: ease all 0.3s;
  opacity: 0.3;
  z-index: 1;
}
:deep(.slick-arrow.custom-slick-arrow:before) {
  display: none;
}
:deep(.slick-arrow.custom-slick-arrow:hover) {
  color: #fff;
  opacity: 0.5;
}

:deep(.slick-slide h3) {
  color: #fff;
}

/* 移动端优化 */
@media (max-width: 1024px) {
  :deep(.slick-slide) {
    height: 120px !important;
    line-height: 120px;
  }

  /* 调整顶部间距适应移动导航栏 */
  .max-w-7xl {
    padding-top: 6rem;
  }
}

/* 小屏幕手机优化 */
@media (max-width: 640px) {
  :deep(.slick-slide) {
    height: 150px !important;
    line-height: 150px;
  }
  .img {
    height: 150px !important;
  }
  .max-w-7xl {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: 5rem;
  }
}
</style>
